// spu

import request from '@/utils/request'
import type {
  HasSpuResponseData,
  AllTradeMarkData,
  SpuImgData,
  SaleAttrResponseDate,
  HasSaleAttrData,
  SpuData,
} from './type'
enum API {
  HASSPU_URL = '/admin/product/',
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  IMAGESPU_URL = '/admin/product/spuImageList/',
  SALEATTR_URL = '/admin/product/spuSaleAttrList/',
  SPUSALEATTR_URL = '/admin/product/baseSaleAttrList',
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  DELETESPU_URL = '/admin/product/deleteSpu/',
}

export const reqHasSpu = (
  page: number,
  limit: number,
  category3Id: number | string,
) => {
  return request.get<any, HasSpuResponseData>(
    API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`,
  )
}
export const reqAllTradeMark = () => {
  return request.get<any, AllTradeMarkData>(API.ALLTRADEMARK_URL)
}

export const reqSpuImage = (spuId: number) => {
  return request.get<any, SpuImgData>(API.IMAGESPU_URL + spuId)
}

export const reqSaleAttr = (spuId: number) => {
  return request.get<any, SaleAttrResponseDate>(API.SALEATTR_URL + spuId)
}

export const reqSaleAttrList = () => {
  return request.get<any, HasSaleAttrData>(API.SPUSALEATTR_URL)
}

export const reqAddOrUpdateSpu = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}

export const reqDeleteSpu = (spuId: number) => {
  return request.delete<any, any>(API.DELETESPU_URL + spuId)
}
